/**
 * 微信类别js
 */

$(function() {
	initialPage();
	getGrid();
});

function initialPage() {
	$(window).resize(function() {
		$('#dataGrid').bootstrapTable('resetView', {
			height : $(window).height() - 56
		});
	});
}

function getGrid() {
	$('#dataGrid').bootstrapTableEx({
		url : '../../sys/wcategory/list?_' + $.now(),
		height : $(window).height() - 56,
		queryParams : function(params) {
			params.name = vm.keyword;
			return params;
		},
		columns : [ {
			checkbox : true
		}, {
			field : "createTime",
			title : "创建时间",
			width : "100px"
		},{
			field : "img",
			title : "类别图片",
			width : "100px"
		}, {
			field : "categoryId",
			title : "编号",
			width : "100px"
		},  {
			field : "name",
			title : "类别名称",
			width : "100px"
		}, {
			field : "price",
			title : "价格",
			width : "100px"
		}, {
			field : "priceRange",
			title : "价格区间",
			width : "100px"
		}, {
			field : "orderNum",
			title : "排序",
			width : "100px"
		} ]
	})
}

var vm = new Vue({
	el : '#dpLTE',
	data : {
		keyword : null
	},
	methods : {
		load : function() {
			$('#dataGrid').bootstrapTable('refresh');
		},
		save : function() {
			dialogOpen({
				title : '新增微信类别',
				url : 'base/wcategory/add.html?_' + $.now(),
				width : '420px',
				height : '450px',
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});
		},
		edit : function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections');
			if (checkedRow(ck)) {
				dialogOpen({
					title : '编辑微信类别',
					url : 'base/wcategory/edit.html?_' + $.now(),
					width : '420px',
					height : '450px',
					success : function(iframeId) {
						top.frames[iframeId].vm.wCategory.id = ck[0].id;
						top.frames[iframeId].vm.setForm();
					},
					yes : function(iframeId) {
						top.frames[iframeId].vm.acceptClick();
					}
				});
			}
		},
		remove : function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];
			if (checkedArray(ck)) {
				$.each(ck, function(idx, item) {
					ids[idx] = item.id;
				});
				$.RemoveForm({
					url : '../../sys/wcategory/remove?_' + $.now(),
					param : ids,
					success : function(data) {
						vm.load();
					}
				});
			}
		}
	}
})